package lec08ds;

public class UniLinkedList {
    private static class Node {
        int data;
        Node next;

        public Node(int data, Node next) {
            this.data = data;
            this.next = next;
        }

        public Node(int data) {
            this(data, null);
        }
    }

    Node head = null;
    int size = 0;

    void addFirst(Node node) {
        if (head == null) {
            head = node;
            ++size;
            return;
        }
        node.next = head;
        head = node;
        ++size;
        return;

    }

    void show() {
        Node node = head;
        while (node != null) {
            System.out.println(node.data);
            node = node.next;
        }
    }


    public static void main(String[] args) {
        UniLinkedList list = new UniLinkedList();
        for (int i = 0; i < 10; i++) {
            list.addFirst(new Node(i));
        }
        list.show();
    }
}
